package books.to.africa
import grails.plugins.springsecurity.Secured

class BookController {
  def springSecurityService

	def scaffold = true
//    def index = {redirect (action:home)}
//    def home = {render(view: "donateBook.gsp")}


	def donateBook = {
Date thedate = new Date()
DonorRegister you = currentUser()
        def newbook = 
                        new Book (
                                title: params.title,
                                author: params.author,
                                quantity: params.quantity,
                                description: params.description,
                                ISBN: params.ISBN,
                                minGradeLevel: params.minGradeLevel,
                                maxGradeLevel: params.maxGradeLevel,
                                language: params.language,
                                category: params.category,
                                ranking: params.ranking,
                                dateListed : thedate,
                                ).save(failOnError:true)
			you.addToBooks(newbook)
			render "ur book is donated"
			//tODO: add to inventory list


}

  private currentUser(){
        return User.get(springSecurityService.principal.id)
}

	
}
